//
//  JsonAnimation.swift
//  KaiChat
//
//  Created by lx on 2023/11/1.
//

import UIKit
import Lottie

class JsonAnimationView: UIView {
    
    @objc public var animationView: AnimationView!
    @objc public var fileName: String?
 
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    @objc public convenience init(name: String) {
        self.init(frame: .zero)
        fileName = name
        self.animationView = AnimationView(name: name)
        addSubview(self.animationView)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        animationView.frame = self.bounds;
    }
    
    @objc public func play(complete: @escaping (Bool) -> Void) -> Void {
        if animationView.isAnimationPlaying {
            return
        }
        animationView.play(completion: complete)
    }
    
    @objc public func pause() -> Void {
        animationView?.pause();
    }
    
    @objc public func stop() -> Void {
        animationView?.stop();
    }
    
}
